<template>
	<van-empty description="暂无收藏" image="https://fastly.jsdelivr.net/npm/@vant/assets/custom-empty-image.png" v-if="list.length==0"/>
	<scroll-view scroll-y="true" @scrolltolower="lowerBottom" style="height: 100vh;" v-else refresher-enabled="true"
		:refresher-triggered="triggered" @refresherrefresh="onRestore">
		<view class="meslist" v-for="(item,index) in list" :key="item.userid">
			<mes :title='item.title' :content='item.content' :pic="item.img" :id='item.mesid' :time='item.time' :types='item.types'></mes>
		</view>
	</scroll-view>
</template>

<script>
	import mes from '@/modul/common/message.vue'
	import {getMyfavoritepost} from '@/store/api.js'
		import {truncateString} from '@/store/constants.js'
	export default {
		mounted() {
			getMyfavoritepost(1, 20).then(res => {
				// const re=JSON.parse(res)
				console.log('这是收藏的')
				console.log(res)
				this.num++
				this.total=res.data.data.total
				res.data.data.rows.forEach(item => {
					let types = ''
					item.tags.forEach(it => {
						types = types + '#' + it.name
					})
					this.list.unshift({
						img: item.posterAvatar,
						title: item.title,
						content: truncateString(item.content),
						mesid: item.id,
						status: item.status,
						userid:item.posterId,
						time:item.beginTime,
						types:types
					})
				})
			}).catch(err => {
				console.log(err)
			})
		},
		components: {
			mes
		},

		data() {
			return {
				num: 1,
				all: 0,
				list: [
				],
				triggered:false
			}
		},
		methods:{
			onRestore(){
				this.triggered=true
				this.num= 1
				this.all= 0
				this.list= [
				]
				getMyfavoritepost(1, 20).then(res => {
					// const re=JSON.parse(res)
					console.log('这是收藏的')
					console.log(res)
					this.num++
					this.total=res.data.data.total
					res.data.data.rows.forEach(item => {
						let types = ''
						item.tags.forEach(it => {
							types = types + '#' + it.name
						})
						this.list.unshift({
							img: item.posterAvatar,
							title: item.title,
							content: truncateString(item.content),
							mesid: item.id,
							status: item.status,
							userid:item.posterId,
							time:item.beginTime,
							types:types
						})
					})
				}).catch(err => {
					console.log(err)
				})
				setTimeout(()=>{
					this.triggered=false
				},1000)
			},
			lowerBottom() {
				if (this.total > this.list.length) {
					getMypost(this.num, 20).then(res => {
						this.num++
						res.data.data.rows.forEach(item => {
							let types = ''
							item.tags.forEach(it => {
								types = types + '#' + it.name
							})
							this.list.unshift({
								img: item.posterAvatar,
								title: item.title,
								content: truncateString(item.content),
								mesid: item.id,
								status: item.status,
								userid:item.posterId,
								time:item.beginTime,
								types:types
							})
						})
					}).catch(err => {
						console.log(err)
					})
				}
			},
			showdetail(item){
				// uni.$emit('showdialog',item)
				console.log(item)
				uni.navigateTo({
					url:`/subpkg/mes_detail/mes_detail?id=${item.id}`
				})
			}
		}
	}
</script>

<style>

</style>
